package com.appli.fastitin;

import java.util.Locale;


import android.animation.AnimatorSet.Builder;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.text.InputType;
import android.text.Layout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {
int i=1;

   //SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
   ViewPager mViewPager;
	   EditText e[]=new EditText[10];
	   final String adresse = "adresse";
	       @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the app.
        //mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
       e[0]=(EditText)findViewById(R.id.address);
        // Set up the ViewPager with the sections adapter.
      // mViewPager = (ViewPager) findViewById(R.id.pager);
       // mViewPager.setAdapter(mSectionsPagerAdapter);
       final Button button_Ajout = (Button) findViewById(R.id.Ajout);
       button_Ajout.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
        	   LinearLayout layout = (LinearLayout)findViewById(R.id.addr);  
        	   
      	   AlertDialog.Builder monDialogue = new AlertDialog.Builder(MainActivity.this);
	 	        //monDialogue.setTitle("mon titre");
		      //  monDialogue.setMessage("mon msg"+(e[0].getText().toString().length()> 0) +"l");
		      //  monDialogue.show();
        		  
        			   if(e[i-1].getText().toString().trim().length()> 0){
        	         	   
			        	   e[i]= new EditText(getApplicationContext());
			        	  //e[i].setText("Adresse "+i);
			        	   e[i].setHint("Adresse "+(i+1));
			        	   e[i].setInputType(InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
			               layout.addView(e[i]);
			               i++;
        			   }
        			   else{
        			    monDialogue = new AlertDialog.Builder(MainActivity.this);
        		        monDialogue.setTitle("Champs Manquant");
        		        monDialogue.setMessage("Verifier que vous aviez bien rempli tout les champs");
        		        monDialogue.show();
           }}
        });
       
       final Button button_Itin = (Button) findViewById(R.id.Itineraire);
       button_Itin.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               Intent mi = new Intent( MainActivity.this , com.appli.fastitin.recup.class);
               String [] b =new String[i];
               
               for(int j =0 ;j<i;j++){
               b[j]=(e[j].getText()).toString();
               }
               
               mi.putExtra("adresse", b);
               startActivity(mi);
           	   
           }
        });
 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    

    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
   
}
